<template>
    <div class="taxi-content">
        <div class="taxi-location border-top-1px">
            <div class="location">
                <div class="location-item location-to location-item-inputed">
                    <a class="mint-cell mint-field">
                        <div class="mint-cell-wrapper">
                            <div class="mint-cell-title">
                                <span class="mint-cell-text">游玩时间：</span>
                            </div>
                            <div class="mint-cell-value" @input="show_time($event)">
                                <!-- <input type="text" placeholder="请选择生日" @click="openByDrop($event)" v-model="calendar3.display" readonly style="border-width:0px;"> -->
                                <input type="text" placeholder="请选择日期" @click="openByCalendar($event)" v-model="calendar1.display" readonly style="border-width:0px;">

                            </div>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <transition name="fade">
            <div class="calendar-dropdown" :style="{'left':calendar1.left+'px','top':calendar1.top+'px'}" v-if="calendar1.show">
                <!-- <calendar :zero="calendar3.zero" :lunar="calendar3.lunar" :value="calendar3.value" :begin="calendar3.begin" :end="calendar3.end" @select="calendar3.select"></calendar> -->
                <calendar zero="calendar1.zero" :events="calendar1.events" :lunar="calendar1.lunar" :value="calendar1.value" :begin="calendar1.begin" :end="calendar1.end" :weeks="calendar1.weeks" :months="calendar1.months" @select="calendar1.select"></calendar>
            </div>
        </transition>
    </div>
</template>
<script>
// import Icon from 'vue-awesome/components/Icon'
// import tip from '@/components/tip'
// import 'muse-ui/dist/muse-ui.css'
//import 'muse-ui/dist/muse-ui.css'
//import datepicker from '@/components/datepicker/vue-datepicker'
//import computePrice from '@/components/computePrice'
import axios from "axios";
import { Indicator } from "mint-ui";
import { Toast } from "mint-ui";
import { mapActions, mapState, mapGetters } from "vuex";
import calendar from "./calendar.vue";
export default {
  props: ["cpid"],
  data() {
    return {
      popupprice: true,
      // 多选
      calendar5: {
        display: "",
        multi: true,
        show: false,
        zero: true,
        value: [], //默认日期
        lunar: true, //显示农历
        select: value => {
          let displayValue = [];
          value.forEach(v => {
            displayValue.push(v[0] + "-" + (v[1] + 1) + "-" + v[2]);
          });
          this.calendar5.display = displayValue.join(",");
          // this.calendar5.show=false;
          this.calendar5.value = value;
        }
      },
      calendar3: {
        display: "",
        show: false,
        zero: true,
        value: [], //默认日期
        lunar: true, //显示农历
        select: value => {
          this.calendar3.show = false;
          this.calendar3.value = value;
          this.calendar3.display = value.join("-");
          this.$store.dispatch("show_time", this.calendar3.display);
          this.mobile = this.calendar3.display;
          console.log(this.$store.dispatch());
        }
      },
      calendar1: {
        display: "",
        show: false,
        zero: true,
        //lunar:true,
        value: [], //默认日期
        // lunar:true, //显示农历
        //weeks:['日', '一', '二', '三', '四', '五', '六'],
        //months:['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        events: {
          // '2017-12-01':'$500',
          // '2017-12-31':'$500',
          // '2018-01-22':'$400',
          // getRiQi:(value)=>{
          //     this.$http.get(url+'api/b/bcsp/jgrl.htm?cpId=3').then((response) => {
          //         console.log('1111111');
          //         this.events=response.data;
          //     })
          // }
        },
        select: value => {
          console.log(value.toString());
          let ticketprice = this.calendar1.events[value.join("-")].sj;
          let ticketcount = this.calendar1.events[value.join("-")].kc;
          console.log("售价..."+ticketprice); //售价
          console.log("库存..."+ticketcount); //库存
          this.$emit("ticketprice", ticketprice);

          this.calendar1.show = false;
          this.calendar1.value = value;
          this.calendar1.display = value.join("-");
          this.$store.dispatch("show_time", this.calendar1.display);
          this.mobile = this.calendar1.display;
          console.log("日期..."+this.mobile);
          let buydate = this.mobile;
          this.$emit("buydate", buydate);
        }
      }
    };
  },
  computed: {
    ...mapState(["position", "address"])
  },
  watch: {
    position(oldVal, newVal) {}
  },
  methods: {
    closecalender() {
      this.$emit("popupprice", false);
    },
    show_suggestshow_suggest(key) {
      console.log(key);
      this.$store.dispatch("show_suggest", key);
      this.$router.push({ path: "/suggest" });
    },
    show_calendar() {
      //this.$store.dispatch('show_suggest',key)
      console.log("1111111");
      this.$router.push({ path: "/app" });
    },
    show_time(e) {
      console.log(e);
      this.$store.dispatch("show_time", e);
      this.mobile = e;
      console.log(this.mobile);
      //   console.log("00000000000000000000000")
      //   this.$store.dispatch('show_time')
      //   this.$router.push({path: './calendar'})
    },
    openMultiByDrop(e) {
      this.calendar5.show = true;
      this.calendar5.left = e.target.offsetLeft - 86;
      this.calendar5.top = e.target.offsetTop + 130;
      e.stopPropagation();
      window.setTimeout(() => {
        document.addEventListener(
          "click",
          e => {
            this.calendar5.show = false;
            document.removeEventListener("click", () => {}, false);
          },
          false
        );
      }, 1000);
    },
    openByDrop(e) {
      console.log(e);
      this.calendar3.show = true;
      this.calendar3.left = e.target.offsetLeft - 86;
      this.calendar3.top = e.target.offsetTop + 130;

      e.stopPropagation();
      window.setTimeout(() => {
        document.addEventListener(
          "click",
          e => {
            this.calendar3.show = false;
            document.removeEventListener("click", () => {}, false);
          },
          false
        );
      }, 1000);
      console.log(e);
    },
    openByCalendar(e) {
      //events赋值
      console.log(e);
      console.log(this.cpid);
      const url = this.rootUrl;
      axios({
        method: "post",
        url: "/api/mpjgrl1/list.htm",
        params: {
          cpid: this.cpid
        }
      }).then(response => {
        if (response.data.zt === true) {
          console.log(response.data);
          var obj = new Object();
          var json = "{";
          //console.log(response.data.data);
          for (let i = 0; i < response.data.data.length; i++) {
            //onsole.log(response.data.data[i].riqi);
            //obj.push(response.data.data[i].riqi+":"+response.data.data[i].sj);
            var m = new Map();
            console.log("1");
            var key = response.data.data[i].date;
            var value = response.data.data[i].price;
            var stock = response.data.data[i].roomNum;
            //json+="\""+key+"\""+":"+"\""+"￥"+value+"\""+",";
            json +=
              '"' +
              key +
              '"' +
              ":" +
              "{" +
              '"sj"' +
              ":" +
              '"' +
              "￥" +
              value +
              '"' +
              "," +
              '"kc"' +
              ":" +
              '"' +
              stock +
              '"' +
              "}" +
              ",";
            //console.log(json);
            //obj.value=response.data.data[i].sj;
          }
          var json1 = JSON.parse(json.substring(0, json.length - 1) + "}");
          console.log(json.substring(0, json.length - 1) + "}");
          this.calendar1.events = JSON.parse(
            json.substring(0, json.length - 1) + "}"
          );
          console.log(this.calendar1.events);
        } else {
          Indicator.close();
          let instance = Toast({
            message: "加载失败"
          });
          setTimeout(() => {
            instance.close();
          }, 2000);
        }
      });

      //console.log(this.calendar1.events);
      this.calendar1.show = true;
      this.calendar1.left = e.target.offsetLeft - 86;
      this.calendar1.top = e.target.offsetTop + 130;
      //this.calendar1.events={'2018-03-20':'$418','2018-03-21':'$461','2018-03-22':'$511'};
      e.stopPropagation();
      window.setTimeout(() => {
        document.addEventListener(
          "click",
          e => {
            this.calendar1.show = false;
            document.removeEventListener("click", () => {}, false);
          },
          false
        );
      }, 1000);
    },
    test(e) {
      console.log(11111111);
      this.$store.dispatch("show_time", e);
      console.log(e);
      this.mobile = e;
      console.log(this.mobile);
    },
    test1(e) {
      console.log(222222);
      console.log(e);
      this.mobile1 = e;
      console.log(this.mobile1);
    }
  },
  watch: {
    birthday() {
      console.log(this.$birthday);
    }
  },
  components: {
    calendar
  },
  beforeCreated() {}
};
</script>
<style scoped>
.fa-icon {
  vertical-align: middle;
}
.taxi-content {
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: #999;
  background-color: #fff;
  text-align: left;
}
.border-bottom-1px,
.border-left-1px,
.border-right-1px,
.border-top-1px {
  position: relative;
}
.border-bottom-1px:after,
.border-bottom-1px:before,
.border-left-1px:after,
.border-left-1px:before,
.border-right-1px:after,
.border-right-1px:before,
.border-top-1px:after,
.border-top-1px:before {
  content: "";
  display: block;
  position: absolute;
  transform-origin: 0 0;
}
.border-top-1px:before {
  border-top: 1px solid #ebebeb;
  left: 0;
  top: 0;
  width: 100%;
}
.location {
  font-size: 16px;
  line-height: 1;
  color: #fc9153;
  background-color: #fff;
}
.location-item {
  position: relative;
  padding-left: 38px;
  padding-right: 16px;
}
.location-item:before {
  content: "";
  position: absolute;
  top: 50%;
  left: 16px;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background-color: #3cbca3;
}
.location-field {
  padding: 17px 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.border-bottom-1px:after {
  border-bottom: 1px solid #ebebeb;
  left: 0;
  bottom: 0;
  width: 100%;
  transform-origin: 0 bottom;
}
.location-item-inputed {
  color: #666;
}
.location-item:before {
  content: "";
  position: absolute;
  top: 50%;
  left: 16px;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background-color: #3cbca3;
}
.location-to:before {
  background-color: #fc9153;
}
.location-field {
  padding: 17px 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.taxi-rule {
  position: relative;
  height: 50px;
  line-height: 50px;
  text-align: center;
  color: #666;
}
.taxi-rule > span {
  vertical-align: middle;
}
.mint-cell-wrapper {
  padding-left: 0px !important;
  padding-right: 0px !important;
}
.mint-header {
  background-color: #fc9153;
}
.mint-search {
  height: 0vh;
}
.mu-text-field-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
  border: 0;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  outline: 0;
  line-height: 1.6;
  font-size: inherit;
  width: 100%;
  height: 0px;
}
.mu-text-field-line {
  margin: 0;
  height: 0px;
  border: none;
  background-color: rgba(0, 0, 0, 0.12);
  left: 0;
  right: 0;
  position: absolute;
}
.mu-text-field-focus-line {
  height: 0px;
}
.mu-text-field-content {
  padding-bottom: 0px;
}
.mu-popover {
  left: 133px;
}

.flex {
  box-sizing: border-box;

  display: -webkit-box;

  display: -webkit-flex;
  -webkit-justify-content: space-between;
  -webkit-align-items: top;

  display: flex;
  justify-content: space-between;
  align-items: top;
  flex-flow: row wrap;
}
.flex > div {
  margin: 10px;
  padding: 20px;
  width: 25%;
  min-width: 300px;
  border: 1px solid #eee;
  border-radius: 2px;
  position: relative;
}
.flex > div > span {
  position: absolute;
  left: 0px;
  top: 0px;
  padding: 5px 10px;
  font-family: "PingFang SC", "Hiragino Sans GB", "STHeiti", "Microsoft YaHei",
    "WenQuanYi Micro Hei", sans-serif;
  font-size: 10px;
  border-radius: 0 0 2px 0;
  background: #ea6151;
  color: #fff;
}
.flex > div > input {
  box-sizing: border-box;
  width: 100%;
  margin-top: 20px;
  border-radius: 2px;
  border: 1px solid #dedede;
  padding: 10px;
  font-size: 16px;
  background: url()
    no-repeat 8px 10px;
  padding-left: 36px;
  color: #666;
}

/*transition*/
.fade-enter-active,
.fade-leave-active {
  transition: all 0.5s ease-in-out;
}
.fade-enter,
.fade-leave-active {
  opacity: 0;
  transform: translateY(-10px);
}

/*下拉框*/
.calendar-dropdown {
  background: #fff;
  top: 40;
  border: 1px solid #eee;
  border-radius: 2px;
  z-index: 1;
}
.calendar-dropdown:before {
  position: absolute;
  left: 30px;
  top: -10px;
  content: "";
  border: 5px solid rgba(0, 0, 0, 0);
  border-bottom-color: #dedede;
}
.calendar-dropdown:after {
  position: absolute;
  left: 30px;
  top: -9px;
  content: "";
  border: 5px solid rgba(0, 0, 0, 0);
  border-bottom-color: #fff;
}

/*弹出框*/
.calendar-dialog {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}

.calendar-dialog-mask {
  background: rgba(255, 255, 255, 0.5);
  width: 100%;
  height: 100%;
}

.calendar-dialog-body {
  background: #fff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 2px;
}
</style>